package com.xiaotu.DatePage;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author xiaotu
 * @Description //TODO
 * @Date 2022/4/1 16:37
 * @ClassName Date01
 * @Version 1.0
 * 日期操作
 **/
public class Date01 {
    public static void main(String[] args) {
        Date date = new Date();
        //获取当前系统时间
        System.out.println(date.getTime());
        //方式二
        System.out.println(System.currentTimeMillis());
        //转换成指定的格式
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        System.out.println(format);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        //显示年份
        int i = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int dates = calendar.get(Calendar.DATE);
        System.out.println(i);
        System.out.println(month+1);
        System.out.println(dates);

    }
}
